package com.akilesa.dictcreator;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: akilesa
 * Date: 19.01.2010
 * Time: 11:47:40
 * To change this template use File | Settings | File Templates.
 */

public class EnglishWordTokenizerResult {

    private List<WordDescription> words = new ArrayList<WordDescription>();

    public void printToConsole() {
        System.out.println("Total words: " + getTotal());
        for (WordDescription item : words) {
            item.printToConsole();
        }
    }

    public void excludeFrequencyOne() {
        List<WordDescription> removal = new ArrayList<WordDescription>();
        for (WordDescription item : words) {
            if (item.getCount() == 1) {
                removal.add(item);
            }
        }
        words.removeAll(removal);
        Statistic.getInstance().setWordExcludedCount(Statistic.getInstance().getWordExcludedCount() + removal.size());
    }

    public static class WordDescription {
        private String word;
        private long count;

        WordDescription() {

        }

        WordDescription(String word, long count) {
            this.count = count;
            this.word = word;
        }

        public void printToConsole() {
            System.out.println(word + "\t" + count);
        }

        public String getWord() {
            return word;
        }

        public void setWord(String word) {
            this.word = word;
        }

        public long getCount() {
            return count;
        }

        public void setCount(long count) {
            this.count = count;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;

            WordDescription that = (WordDescription) o;

            if (count != that.count) return false;
            if (word != null ? !word.equals(that.word) : that.word != null) return false;

            return true;
        }

        @Override
        public int hashCode() {
            int result = word != null ? word.hashCode() : 0;
            result = 31 * result + (int) (count ^ (count >>> 32));
            return result;
        }
    }

    public long getTotal() {
        return words.size();
    }

    public List<WordDescription> getWords() {
        return words;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        EnglishWordTokenizerResult that = (EnglishWordTokenizerResult) o;

        if (words != null ? !words.equals(that.words) : that.words != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return words != null ? words.hashCode() : 0;
    }
}
